var whirMain = {
	fontsize: function () {
		var arr = []
		for (let index = 0; index < 81; index++) {
			if (index >= 10) {
				arr.push(index / 100 + 'rem')
			}
		}
		var $style = $('<style>', { type: 'text/css' }).appendTo('head');
		// 构建 :root 样式字符串
		var rootStyles = ':root {\n';
		for (var i = 10; i <= 80; i++) {
			rootStyles += '--font-size' + i + ':' + arr[i - 10] + ';';
		}
		rootStyles += '}';
		// 设置样式内容
		$style.html(rootStyles);
	},
	apple:function(width){
	    function isMac() {
			return /Macintosh|MacIntel|MacPPC|Mac68K/.test(navigator.userAgent);
		}
		if (isMac()) {
			$('html').addClass('isMac');
		   function updateFontSize() {
			// 获取视口宽度
			var viewportWidth = window.innerWidth;
			if(viewportWidth<width){
			// 根据公式计算字体大小
			   var fontSize = (100 / width) * viewportWidth;
			   // 设置给 html 元素
				$('html').css('font-size',fontSize + 'px');
			}else{
			   $('html').removeAttr("style")
			}
			}
	
			// 初始化字体大小
			updateFontSize();
	
			// 监听窗口大小变化，包括缩放
			window.addEventListener('resize', updateFontSize);
		}	
	},
	top: function () {
		$("#m" + m).addClass("aon");//二级菜单选中
		whirOpen.toggle(".open-search", "body", "search-show", ".top-search .box");
		whirOpen.toggle(".open-menu", "body", "menu-show", "menu");
		whirMain.menu();


	},
	menu:function(){
		$("menu li").each(function () {
			var n = $(this).find(".sub").find("dd").length
			if (n >= 1) {
				$(this).addClass("has-sub");
				$(this).find("span").append("<i class='wap-op'></i>");
				$(this).hover(function () {
					$(this).addClass("active").siblings().removeClass("active");
				}, function () {
					$(this).removeClass("active");
				});
			}
		});

		$(".wap-op").click(function () {
			$(this).parents("span").toggleClass("on");
			$(this).parent("span").next(".sub").slideToggle();
			$(this).parents("li").siblings().find("span").removeClass("on");
			$(this).parents("li").siblings().find(".sub").slideUp();
		});		
	},
	bottom: function (a,b,c,d) {
		//搜索功能
		// whirSearch.one("#TopBtn", "TopKey", a, b, c, d, searchpath)
		//截取字符
		$("[data-dots]").each(function () {
			var n = $(this).data("dots")
			$(this).css("--wlc", n);
			$(this).addClass("dots-n");
		});
		//整站无图处理
		$.each($("img"), function (i, n) {
			$(n).on('error', function () {
				n.src = nopicpath;
			});
			n.src = n.src;
		});

        // 高度元素
        $('.h').each(function() {
            let isHeight = $(this).attr('data-height');
            $(this).css({height: isHeight+'rem'})
        })
	},
	home: function () {
		var splide = new Splide('.home-ban', { arrows: false });
		splide.mount();
	}
}

//搜索插件
var whirSearch = {
	one: function (btn, kid, txt, txt1, txt2, txt3, url) {
		$(btn).jqSearch({
			TxtVal: txt,
			KeyTxt1: txt1,
			KeyTxt2: txt2,
			KeyTxt3: txt3,
			KeyId: kid, //输入框id
			KeyUrl: url, //跳转链接
			KeyHref: "key", //链接传值
			Static: false //是否静态站
		});
	}
}
//打开效果
var whirOpen = {
	toggle: function (btn, main, css, out) {
		$(btn).click(function (e) {
			$(main).toggleClass(css);
			$(document).on("click", function () {
				$(main).removeClass(css);
			});
			e.stopPropagation();
		});
		$(out).on("click", function (e) {
			e.stopPropagation();
		});
	},
	fade: function (a, b) {
		$(a).click(function (e) {
			$(this).toggleClass("on");
			$(b).stop(true, true).fadeToggle();
			$(document).on("click", function () {
				$(b).stop(true, true).fadeOut();
				$(a).removeClass("on");
			});
			e.stopPropagation();
		});
		$(b).on("click", function (e) {
			e.stopPropagation();
		});
	},
	hover: function (a) {
		$(a).hover(function () {
			$(this).addClass("active");
		}, function () {
			$(this).removeClass("active");
		});
	},
	video: function () {
		//视频弹窗
		$(".play").click(function (e) {
			var files = $(this).data("files");
			$(".video-box").remove();
			$('body').append("<div class='video-box flex-aic-jcc'><div class='close'></div><section class='inner'><video src='" + files + "' controls autoplay  x-webkit-airplay='true' x5-video-player-type='h5' x5-video-player-fullscreen='true' webkit-playsinline='true' playsinline='true'></video></section></div>");
			$('body').css("overflow", "hidden");
			videoclose();
		});

		function videoclose() {
			$(".video-box .close").click(function (e) {
				$(".video-box").remove();
				$('body').css("overflow", "auto");
			});
		}
	}
}
